# encoding: utf-8
import SocketServer
import sys


class MyUDPHandler(SocketServer.BaseRequestHandler):

    def handle(self):
        print("{}\t{}".format(self.client_address[0], self.request[0].strip()))


if __name__ == "__main__":
    HOST = "0.0.0.0"
    PORT = 9696
    if len(sys.argv) > 1:
        arg1 = sys.argv[1]
        if arg1.isdigit():
            PORT = int(sys.argv[1])
    else:
        pass;

    server = SocketServer.UDPServer((HOST, PORT), MyUDPHandler)
    print("服务器启动,端口{}，等待接受数据".format(PORT))
    server.serve_forever()
